class OrdersController < ApplicationController
  
  def find_all
    render :amf => Order.find(:all)
  end

  # expect single argument: product id
  def find_by_id
    render :amf => Order.find(params[:id])
  end

  # saves new and updates existing Orders
  # expect params[0] to be incoming Orders
  def save
    @order = params[0]

    if @order.save
      render :amf => @order
    else
      render :amf => FaultObject.new(@order.errors.full_messages.join('\n'))
    end
  end

  # expect single argument: order id
  def destroy
    @order = Order.find(params[:id])
    @order.destroy

    render :amf => true
  end
  
  def validate_card
    #see config/rubyamf_config.rb for how to map named params
    valid_card = complex_validation_algorithm(params[:card_holder], params[:card_number])
    render :amf => valid_card
  end
  
 private
  
  def complex_validation_algorithm(card_holder, card_number)
    true
  end
  
end
